package com.mdd.car.controller;

import com.mdd.car.params.CarModelsParam;
import com.mdd.car.service.ICarModelsService;
import com.mdd.car.vo.CarModelsVo;
import com.mdd.common.aop.NotPower;
import com.mdd.common.base.page.PageValidate;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validate.AddGroup;
import com.mdd.common.validate.EditGroup;
import com.mdd.common.validate.IdsValidate;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

/**
 * 车型管理
 *
 * @Description
 * @Author 幻速
 * @Date 2024/3/13 13:43
 **/
@RestController
@RequestMapping("api/system/car/model")
@Api(tags = "车型管理")
public class SysCarModelController {
    @Resource
    ICarModelsService carModelsService;
    @NotPower
    @GetMapping("/all")
    @ApiOperation(value="所有车型")
    public AjaxResult<List<CarModelsVo>> all() {
        List<CarModelsVo> list = carModelsService.all();
        return AjaxResult.success(list);
    }
    @NotPower
    @GetMapping("/list")
    @ApiOperation(value="车型列表")
    public AjaxResult<PageResult<CarModelsVo>> list(@Validated PageValidate pageValidate,String name) {
        PageResult<CarModelsVo> list = carModelsService.list(pageValidate,name);
        return AjaxResult.success(list);
    }
    @NotPower
    @PostMapping("/add")
    @ApiOperation(value="车型新增")
    public AjaxResult<Object> add(@Validated(value = AddGroup.class) @RequestBody CarModelsParam carBrandParam) {
        carModelsService.add(carBrandParam);
        return AjaxResult.success();
    }
    @NotPower
    @PostMapping("/edit")
    @ApiOperation(value="车型编辑")
    public AjaxResult<Object> edit(@Validated(value = EditGroup.class) @RequestBody CarModelsParam carBrandParam) {
        carModelsService.edit(carBrandParam);
        return AjaxResult.success();
    }
    @NotPower
    @PostMapping("/del")
    @ApiOperation(value="车型删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdsValidate idValidate) {
        carModelsService.del(idValidate.getIds());
        return AjaxResult.success();
    }
}
